package com.aiju.cash.core.api;

import com.aiju.app.callback.HttpCallback;
import com.aiju.common.http.interceptor.HttpFactory;
import com.aiju.widgit.dialog.DialogHelper;

import java.util.HashMap;
import java.util.Map;

import static com.aiju.app.config.ConfigManager.INIT_SERVER_HOST;

/**
 * @author: 佐为
 * @date: 2017-03-27 10:14
 * @version: V1.0
 * @Description: 优惠折扣
 */
public class DiscountApi extends BaseApi {

    private String singleDiscount = INIT_SERVER_HOST + "/discount/singleDiscount";
    private String updateSwitch = INIT_SERVER_HOST + "/discount/updateSwitch";
    private String save = INIT_SERVER_HOST + "/discount/save";
    private String delete = INIT_SERVER_HOST + "/discount/delete";
    private String list = INIT_SERVER_HOST + "/discount/list";

    private HttpFactory instance;

    public DiscountApi(DialogHelper dialogHelper) {
        super(dialogHelper);
        instance = HttpFactory.getInstance();
        instance.setDialogHelper(dialogHelper);
    }

    public void setDialogHelper(DialogHelper dialogHelper) {
        instance.setDialogHelper(dialogHelper);
    }

    /**
     * 某个优惠折扣列表接口
     *
     * @param type
     * @param callback
     */
    public void singleDiscount(String type, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("token", mUser.getToken());
        map.put("storeId", mUser.getStoreId());
        map.put("type", type);
        instance.makeProxy().requestPost(singleDiscount, map, callback);
    }

    /**
     * 更新某个优惠折扣的开关接口
     *
     * @param type
     * @param callback
     */
    public void updateSwitch(String type, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("token", mUser.getToken());
        map.put("storeId", mUser.getStoreId());
        map.put("type", type);
        instance.makeProxy().requestPost(updateSwitch, map, callback);
    }

    /**
     * 优惠折扣删除接口
     *
     * @param id
     * @param callback
     */
    public void delete(String id, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("id", id);
        map.put("token", mUser.getToken());
        map.put("storeId", mUser.getStoreId());
        instance.makeProxy().requestPost(delete, map, callback);
    }

    /**
     * 更新某个优惠折扣的开关接口
     *
     * @param type
     * @param condition 优惠需要满足的条件
     * @param callback
     */
    public void save(String type, String condition, String value, HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("storeId", mUser.getStoreId());
        map.put("value", value);
        map.put("condition", condition);
        map.put("type", type);
        map.put("token", mUser.getToken());
        instance.makeProxy().requestPost(save, map, callback);
    }

    /**
     * 优惠折扣列表接口
     * @param callback
     */
    public void list(HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("token", mUser.getToken());
        map.put("storeId", mUser.getStoreId());
        map.put("operatorId", mUser.getOperatorId());
        instance.makeProxy().requestPost(list, map, callback);
    }
}
